import 'package:flutter/material.dart';
import 'package:flutter02/res/list_data.dart';

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  Widget _initListData(context, index) {
    return Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(border: Border.all(color: Colors.black26)),
      child: Column(
        children: [
          SizedBox(
            height: 140,
            child: Image.network(
              listData[index]["imageUrl"],
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            height: 30,
            child: Text(
              listData[index]['title'],
              style: const TextStyle(color: Colors.blue, fontSize: 18),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      itemCount: listData.length,
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        crossAxisSpacing: 10,
        mainAxisSpacing: 10,
        childAspectRatio: 0.9,
      ),
      padding: const EdgeInsets.all(10),
      // crossAxisSpacing: 10,
      // mainAxisSpacing: 10,
      // childAspectRatio: 0.9,
      // crossAxisCount: 2,
      // // maxCrossAxisExtent: 180,
      // children: _initListData(),
      itemBuilder: _initListData,
    );
  }
}
